import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
class JpushManager{
  JPush jpush ;

  // 工厂模式
  factory JpushManager() =>_getInstance();
  static JpushManager get instance => _getInstance();
  static JpushManager _instance;
  JpushManager._internal() {
    jpush = new JPush();
    this.jpush.addEventHandler(
      // 接收通知回调方法。
      onReceiveNotification: (Map<String, dynamic> message) async {
        print("flutter onReceiveMessage: $message");
      },
      // 点击通知回调方法。
      onOpenNotification: (Map<String, dynamic> message) async {
        print("flutter onReceiveMessage: $message");
      },
      // 接收自定义消息回调方法。
      onReceiveMessage: (Map<String, dynamic> message) async {
        print("flutter onReceiveMessage: $message");
      },
    );
    this.jpush.setup(
      appKey: "f8291a62d25590a2531f6309",
      channel: "theChannel",
      production: false,
      debug: true, // 设置是否打印 debug 日志
    );
    jpush.getRegistrationID().then((rid) {
      print("registrationId"+rid);
    });
    jpush.applyPushAuthority(new NotificationSettingsIOS(
        sound: true,
        alert: true,
        badge: true));
  }
  static JpushManager _getInstance() {
    if (_instance == null) {
      _instance = new JpushManager._internal();
    }
    return _instance;
  }
}